import Vue from 'vue'
import Router from 'vue-router'
import Home from '../pages/Home.vue'
import Category from '../pages/Category.vue'
import Shopcart from '../pages/Shopcart.vue'
import User from '../pages/User.vue'



Vue.use(Router)

const routes= [
  { path: '/', redirect: '/home', meta: { title: '首页' } },
  { path: '/home', component: Home, name: 'home', meta: { title: '首页' } },
  { path: '/category', component: Category, name: 'category', meta: { title: '分类' } },
  { path: '/shopcart', component: Shopcart, name: 'shopcart', meta: { title: '购物车' } },
  { path: '/user', component: User, name: 'user', meta: { title: '我的' } }
]

var router = new Router({
  routes,
  linkActiveClass: 'mui-active'
})


router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
